//
//  FortySixTableViewCell.m
//  QuickReadComic
//
//  Created by 苗钧豪 on 16/9/1.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "FortySixTableViewCell.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
#import "UIImage+WebP.h"

@implementation FortySixTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self NetworkRequests];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    [layout setItemSize:CGSizeMake((self.bounds.size.width - 30), (self.bounds.size.height - 10))];
    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 0);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    [self.fortySixCollectionView setCollectionViewLayout:layout];
    [_fortySixCollectionView registerNib:[UINib nibWithNibName:@"FortySixCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"fortysix"];
    _fortySixCollectionView.backgroundColor = [UIColor clearColor];
    _fortySixCollectionView.delegate = self;
    _fortySixCollectionView.dataSource = self;
}
- (void)NetworkRequests {
    [ZWYNetTool GET:@"http://api.kuaikanmanhua.com/v1/topic_new/discovery_list?" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        NSLog(@"=====================成功啦");
        self.model = [dataModel modelWithDic:result[@"data"]];
        [self.fortySixCollectionView reloadData];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"=====================出错啦");
    }];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 46;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    self.cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"fortysix" forIndexPath:indexPath];
    self.topic = self.model.infos[self.Number].topics[indexPath.row];
    [_cell.imgView sd_setImageWithURL:[NSURL URLWithString:_topic.pic]];
    _cell.titleLabel.text = _topic.title;
    _cell.writerLabel.text = _topic.user.nickname;
    _cell.blockLabel.text = _topic.label_text;
    _cell.introLabel.text = _topic.descriptions;
    return self.cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
